I'm new here and i got a very nerving problem..
I have a variable called mysqli_con. It contains the connection to my mysql db.
$mysqli_con = new mysqli(host, user, pw, db);
And i want to ask: Must i type in this variable in every mysqli-code? (for example: mysqli_num_rows or mysql_query)
When i try it with the variable (mysqli_num_rows($mysql_con, ...) -> it works. When i try it without the variable (mysqli_num_rows(....) -> it doesnt work. (requires at least 2 parameters, 1 given in...)
Sorry for the bad english, i live in germany. And new in mysql improved :P
Thanks.
Like @Avinash Babu said you should use the object oriented way.
For example:
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}
$res = $mysqli->query("SELECT 'choices to please everybody.' AS _msg FROM DUAL");
$row = $res->fetch_assoc();
echo $row['_msg'];
Taken from the php manual. http://php.net/manual/de/mysqli.quickstart.dual-interface.php
As a simple answer..
Sure, you would need to add the variables everytime if you are using a procedural way.But its not used commonly used for object orientiated programming approach ..