MySQLi and PDO are object oriented and support Prepared Statements (also support Transactions, Stored Procedures and more). Prepared Statements are very important for web application security, as they protect from SQL injection. Using Prepared Statements you do not have to escape strings before insert them in Database. Moreover, PDO offers support for many databases (not only MySQL). Establish a database connection $DBServer = 'localhost'; // or an IP address $DBUser = 'root'; $DBPass = 'your password'; $DBName = 'dbname'; $conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName); // check connection if ($conn->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } //select rows $sql='SELECT * FROM users'; $rs=$conn->query($sql); $rows_returned = $rs->num_rows; echo $rows_returned; //returns number of rows //loop throu...
OOP,PHP,Web Development,MYSQL,Yii,Bootstrap...Blog.