Home  • Programming • PHP

Which is the better way to connect with mysql database using mysqli

Which is the better way?

<?php
	$db = new MYSQLi("localhost","root","","001");
?>
or //---db_config.php
<?php 
 define('SERVER','localhost'); 
define('USER','root'); 
define('PWD',''); 
define('DB','supershop');
 ?>
//---demo.php
<?php
include_once("config.php");
$db = new MYSQLi(SERVER,USER,PWD,BD);

?>

Comments 8


Second one is the better way to practice because of no need to change database connection string in every file.
ঠিক আছে কিন্তু প্রথমটা যদি আমি config ফাইলে আলাদা করে রেখে পরে হনক্লুড করি $db ব্যবহার করি  তাহলেও আমাকে কোন ডাটা পরিবর্তন করা লাগবে না। তাই আমি জানতে চাইছি কোনটা বেশি ভাল একজন ভাল প্রগ্রামের কাছে?
দুটোই একই ভাবে ব্যবহার করা যাই।
$db object সব page এ available করা insecure
Both are ok. But first method is messy. Use second one
you can add this code in second snipt, then you can use $db objecet....
$db=new mysqli(SERVER,USER,PWD,DGlasses;
You feel better when you use second.

Share

About Author
Abdullah Al Mamun
Copyright © 2024. Powered by Intellect Software Ltd