PHP MYSQL CONNECT PDO

0
84

PHP MYSQL CONNECT PDO

I will show here, how to create simple connection with mysql using PDO PHP 7

PHP supports several databases natively through the PDO or through third party libraries.

The simplest way is to use the PDO to connect to the database.

$connection = new PDO(“mysql:dbname=banco;host=localhost”, “user”,”passwd”);

Shortly after we pass connection attributes

$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);

Now we have MYSQL connection made

TEST $test = $connection->query(“select * from test”);

echo $test->rowCount();

I hope I have helped beginners.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here