lawrence_dev
asked on
Transitioning to PDO/MySQL. Need help with SELECT statement.
How do I make this script work with PDO?
$conn = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->$sql = "SELECT * FROM `manufacturers` WHERE name = '$data[8]'";
foreach($pdo->query($sql) as $row1){
$statement = $conn->prepare("INSERT INTO manufacturers_sku (sku,manufacturer)
VALUES(:sku, :manufacturer)");
$statement->execute(array(
"sku" => $row1['sku'];
"manufacturer" => $row1['sku'];
));
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK got an error...
Parse error: syntax error, unexpected '$results' (T_VARIABLE)
$results->execute(array(
":data" => $data[8] //ERROR THIS LINE
));
How do I fix this error?
Parse error: syntax error, unexpected '$results' (T_VARIABLE)
$results->execute(array(
":data" => $data[8] //ERROR THIS LINE
));
How do I fix this error?
Theres a missing semi colon after this line
$results = $conn->prepare("SELECT * FROM `manufacturers` WHERE name = :data"); // add the semi colon like I have here
ASKER
Thank You!
Why accept a comment that never answered the question or corrected your code, if you want a PDO tutorial there are far better places to go than some generic here's a one for all blah blah
ASKER
I agree Gary! I will take that into consideration next time. I just wanted to reward the time and effort to help. You did get 450 points! The comments that just say "read this" and provide a link don't really help anyone. If I could understand all that overly technical stuff with very little explanation, I would not be paying to be on EE!!! Thanks for helping me with my code! Much appreciated!
There are some things about PHP which are kind of "sine-qua-non." For example we have to assume that anyone asking about conversion to PDO and specifically asking about a SELECT query statement would understand that a PHP "parse error" containing the word "unexpected" indicates an up-stream error in the script. But if the real issue was a PHP parse error, why not just tell us that is your problem? I'd have gladly helped you correct a parse error, too. I just thought there was a PDO-related issue (a very common thing today, since MySQL is going to be killed off soon).
@Gary: If you have something to offer the E-E community that is better than my article, please post it - perhaps write your own article or add your comments to show what my article is missing. I have a great appreciation of constructive criticism and welcome anything you want to add to the conversation!
@Gary: If you have something to offer the E-E community that is better than my article, please post it - perhaps write your own article or add your comments to show what my article is missing. I have a great appreciation of constructive criticism and welcome anything you want to add to the conversation!
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html