php - Query after connecting to remote MySQL database using mysqli_real_connect
I can successfully connect to a remote MySQL database using mysqli_init(), mysqli_ssl_set and mysqlii_real_connect. I can't seem to find an example of a query being done after connecting. The result of mysqli_real_connect is a boolean value, whereas mysqli_connect returns an object representing the connection to the MySQL server. How do I refer to the connection after using mysqli_real_connect? Can anyone provide an example?
<?php error_reporting(E_ALL);
ini_set("display_errors", "1");
$obj = mysqli_init();
mysqli_options($obj, MYSQLI_OPT_CONNECT_TIMEOUT, 5);
mysqli_ssl_set( $obj,
NULL,
NULL,
'ca-cert.pem',
NULL,
NULL);
$link = mysqli_real_connect($obj, 'xxxxxxxxxxxx.com', 'user', 'password, 'database_name');
if (!$link)
{
die('<br /><br />Connect Error (' . mysqli_connect_errno() . ') '.mysqli_connect_error());
} ?>
Answer
Solution:
The way that you'd do it using your example is
mysqli_query($obj, QUERY HERE);
However, you should consider using the OOP (Object Orientated Programming) style, as that would be easier for you to reference within the future.
You would call this class by doing:
And from there on, you could simply call your function by using the following example.