Last active
September 25, 2024 00:21
-
-
Save chales/11359952 to your computer and use it in GitHub Desktop.
Script for a quick PHP MySQL DB connection test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Fill our vars and run on cli | |
# $ php -f db-connect-test.php | |
$dbname = 'name'; | |
$dbuser = 'user'; | |
$dbpass = 'pass'; | |
$dbhost = 'host'; | |
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'"); | |
mysql_select_db($dbname) or die("Could not open the db '$dbname'"); | |
$test_query = "SHOW TABLES FROM $dbname"; | |
$result = mysql_query($test_query); | |
$tblCnt = 0; | |
while($tbl = mysql_fetch_array($result)) { | |
$tblCnt++; | |
#echo $tbl[0]."<br />\n"; | |
} | |
if (!$tblCnt) { | |
echo "There are no tables<br />\n"; | |
} else { | |
echo "There are $tblCnt tables<br />\n"; | |
} |
thanks!
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\inetpub\wwwroot\db-connect-test.php:10
Stack trace:
#0 {main}
thrown in C:\inetpub\wwwroot\db-connect-test.php on line 10
Using on MariaDB Implemented on RaspberryPi
I found this code very helpful i’m new to php and this code was just the job.
Many thanks
Phil
Thank you!
Thanks bro!
Thanks man!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is the error I am getting when I do php.script.php
Fatal error: Uncaught Error: Call to undefined function mysql_connect()