MySQL Forums
Forum List  »  PHP

PHP Connect MySQL Syntax for Retrieving Rows?
Posted by: Arthur Chan
Date: May 22, 2016 01:35PM

Sorry for trivial questions but I am very new to PHP.

I have been able to connect to a remote MySQL database "testdb", but I don't seem to be able to get rows back from test table "testdb.test123".

I've tried variations of syntax, I think it is syntactic error, not sure. Can anyone help?

<?php
$con=mysqli_connect("localhost","scott","tiger","testdb");

if (mysqli_connect_errno($con)) {
 	echo "Failed to connect to MySQL: " . mysqli_connect_error();
} 
else {
	$result = mysqli_query ($con, "SELECT driverlicense, somestate FROM test123 WHERE driverlicense IS NOT NULL");
	if($result == true) {
    		echo '{"query_result":"SUCCESS"}';
    		while($row = mysql_fetch_array($result))
 		 {
  			echo $row['driverlicense'];
  			echo $row['somestate'];
  		}
	}
 	else{
    		echo '{"query_result":"FAILURE"}';
	}
}
	
mysqli_close($con);
?>

Options: ReplyQuote


Subject
Written By
Posted
PHP Connect MySQL Syntax for Retrieving Rows?
May 22, 2016 01:35PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.