02 February 2020

How To convert or change the code and query of MySQL to MySQLi

MySQL Connection =>
$conn = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD ) or die ("Can't connect to database: " . mysql_error());
mysql_select_db (DB_NAME) or die ("tidak bisa pilih database: " . mysql_error());

MySQLi Connection =>
$conn = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die ("Can't connect to database: " . mysqli_error());

MySQL Query =>
$sql = "SELECT blog_id FROM wp_blogs WHERE domain ='iloveu.com'";
$query = mysql_query($sql);

MySQLi Query =>
$sql = "SELECT blog_id FROM wp_blogs WHERE domain ='iloveu.com'";
$query = mysqli_query($conn, $sql);

MySQL fetch data =>
$r = mysql_fetch_array($query);
echo "hi". $r[0];

MySQLi fetch data =>
$r = mysqli_fetch_array($query);
echo "hi". $r[0];

0 komentar:

Post a Comment

Blog Archive