The function of this code is:
Connect to a mysql server with url address localhost and port 3306. The account number of the mysql server is "root" and the password is "9999". There is a database ok on the mysql server, and there is a table abc in the database. Table abc has two columns in total. The column names are "id" and "name". Read out all the data in abc.
The following is the quoted content:
$dbh = @mysql_connect("localhost:3306","root","9999"); /* Define the variable dbh, the mysql_connect() function means to connect to the mysql database, "@" means to block error reporting*/ if(!$dbh){die("error");} /* The die() function means to send the string in brackets to the browser And interrupt the PHP program (Script). The parameters in brackets are the string to be sent. */ @mysql_select_db("ok", $dbh); /* Select a database in the mysql server. The database name selected here is ok */ $q = "SELECT * FROM abc" ; /* Define variable q, "SELECT * FROM abc" is a SQL statement, which means reading data in table abc*/ ?> $rs = mysql_query($q, $dbh); /* Define the variable rs, the function mysql_query() means: send the query string for MySQL to do related processing or execution. Since php is executed from right to left, so, The value of rs is the value returned by the server after running the mysql_query() function*/ if(!$rs){die("Valid result!");} echo "
?> $rs = mysql_query($q, $dbh); while($row = mysql_fetch_object($rs)) echo "$row->id $row->name "; /* id and name can change positions*/ ?> $rs = mysql_query($q, $dbh); while($row = mysql_fetch_array($rs)) echo "$row[id] $row[name] "; /* ID and name can be changed */ ?> @mysql_close($dbh); /* Close the connection to the mysql database*/ ?> |