문제

I am beginning to learn PHP and am attempting to build a shopping cart following a very basic tutorial. I am getting the following error:

Notice: Undefined variable: msqli in C:\Apache\htdocs\products_session.php on line 12

The tutorial I am using describes how to list products from the database, but I do not think this accounts for my database connection which uses PDOs

//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);


$results = $msqli->query("SELECT * FROM practice ORDER BY id ASC");
if ($results) { 
    //output results from database
    while($obj = $results->fetch_object())

here is my connect code

<?php
//connect to your database here
$host = '12.34.56';
$dbname = 'practice';
$user = 'meme';
$pwd = 'slave1';

$conn = new PDO("mysql:host=localhost;dbname=practice", $user, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    if ($conn) {
//echo 'Connected to '.$dbname;
// $conn = null;
} else {
echo 'Failed to connect';
}
?>

I know I don't have $mysqli here but should I replace this with? I tried $conn with no luck. Apologies if this question is very basic. I am only just starting to learn. Thank you.

도움이 되었습니까?

해결책

pdo and mysqli are just database INTERFACES. doesn't matter which you use - the sql will be the same either way.

You cannot mix the two libraries, however. A connection established in one is utterly useless in the other.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top