New to PDO: basic script failing. Including ORDER BY...
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
All the error.log shows is this:
[text][Tue Sep 03 14:34:03.548408 2013] [ssl:warn] [pid 12192:tid 420] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:03.636291 2013] [ssl:warn] [pid 12192:tid 420] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:03.661293 2013] [mpm_winnt:notice] [pid 12192:tid 420] AH00455: Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1 configured -- resuming normal operations
[Tue Sep 03 14:34:03.661293 2013] [mpm_winnt:notice] [pid 12192:tid 420] AH00456: Server built: Feb 23 2013 12:42:00
[Tue Sep 03 14:34:03.661293 2013] [core:notice] [pid 12192:tid 420] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Tue Sep 03 14:34:03.663295 2013] [mpm_winnt:notice] [pid 12192:tid 420] AH00418: Parent: Created child process 11460
AH00548: NameVirtualHost has no effect and will be removed in the next release C:/xampp/apache/conf/extra/httpd-vhosts.conf:46
[Tue Sep 03 14:34:03.948087 2013] [ssl:warn] [pid 11460:tid 308] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:04.002358 2013] [ssl:warn] [pid 11460:tid 308] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:04.028390 2013] [mpm_winnt:notice] [pid 11460:tid 308] AH00354: Child: Starting 150 worker threads.
[/text]
Sadly it means nothing to me.
[text][Tue Sep 03 14:34:03.548408 2013] [ssl:warn] [pid 12192:tid 420] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:03.636291 2013] [ssl:warn] [pid 12192:tid 420] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:03.661293 2013] [mpm_winnt:notice] [pid 12192:tid 420] AH00455: Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1 configured -- resuming normal operations
[Tue Sep 03 14:34:03.661293 2013] [mpm_winnt:notice] [pid 12192:tid 420] AH00456: Server built: Feb 23 2013 12:42:00
[Tue Sep 03 14:34:03.661293 2013] [core:notice] [pid 12192:tid 420] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Tue Sep 03 14:34:03.663295 2013] [mpm_winnt:notice] [pid 12192:tid 420] AH00418: Parent: Created child process 11460
AH00548: NameVirtualHost has no effect and will be removed in the next release C:/xampp/apache/conf/extra/httpd-vhosts.conf:46
[Tue Sep 03 14:34:03.948087 2013] [ssl:warn] [pid 11460:tid 308] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:04.002358 2013] [ssl:warn] [pid 11460:tid 308] AH01909: RSA certificate configured for http://www.example.com:443 does NOT include an ID which matches the server name
[Tue Sep 03 14:34:04.028390 2013] [mpm_winnt:notice] [pid 11460:tid 308] AH00354: Child: Starting 150 worker threads.
[/text]
Sadly it means nothing to me.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
How do I set that:
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: New to PDO: basic script failing. Including ORDER BY...
Lines beginning with a semicolon are commented out. Check beneath those lines for an uncommented value. If not, add
Code: Select all
display_errors OnRe: New to PDO: basic script failing. Including ORDER BY...
I wouldn't worry about those warnings. A missing/invalid RSA cert on a development environment is not causing your issues.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
So is mine set correctly?
What on earth is causing it to not even be triggered in PDO??
As I say, if I use the old style of mysql_, it works. So it's not PHP disabling the code.
It works in test.php. But when I use it as an include, it fails.
What on earth is causing it to not even be triggered in PDO??
As I say, if I use the old style of mysql_, it works. So it's not PHP disabling the code.
It works in test.php. But when I use it as an include, it fails.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
Bingo. Error turned on and here it is. Maybe you can help me enable whatever I have done wrong.Notice: Undefined variable: pdo in C:\xampp\phpMyAdmin\site\includes\menu\home.inc on line 5
Fatal error: Call to a member function query() on a non-object in C:\xampp\phpMyAdmin\site\includes\menu\home.inc on line 5
This is the full script on menu/home.inc:
Code: Select all
<?php
echo "<div class='menuheader'>Categorías</div>";
$query = "SELECT email FROM admin WHERE type = 'admin'";
$result = $pdo->query($query);
var_dump($result); exit;
while ($row = $result->fetch(PDO::FETCH_OBJ)) {
echo "$row->email<br/>";
}
?>Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: New to PDO: basic script failing. Including ORDER BY...
Alright, so $pdo isn't defined. The constructor is being called in dbconn, it's not throwing any exceptions, so it would seem it hasn't been included when this file runs. Have you checked the include order? Is dbconn being included before menu.inc?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
Yes, almost 100 lines before, in index.php.
include "dbconn.php";
...
Is this bit still correct??
As I may have made a mess of this bit:
include "dbconn.php";
...
Code: Select all
<?php
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'sitename');
$sqlconn = mysql_connect(DBHOST, DBUSER, DBPASS);
if ($sqlconn) {
mysql_select_db(DBNAME);
}
try {
$pdo = new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS);
} catch (Exception $e) {
echo 'Could not connect: ' . $e->getMessage();
}
?>As I may have made a mess of this bit:
Code: Select all
......... ';dbname=' .........Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: New to PDO: basic script failing. Including ORDER BY...
That looks fine and would throw an exception if it couldn't connect. Do you have other queries in your index file prior to the inclusion of menu.inc?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
Code: Select all
$cname= isset($_REQUEST['cname']) ? $_REQUEST['cname'] : null;
$sname= isset($_REQUEST['sname']) ? $_REQUEST['sname'] : null;
$c= isset($_REQUEST['c']) ? $_REQUEST['c'] : null;
$s= isset($_REQUEST['s']) ? $_REQUEST['s'] : null;
$h= isset($_REQUEST['h']) ? $_REQUEST['h'] : null;
$prodid= isset($_REQUEST['product']) ? $_REQUEST['product'] : null;
include "dbconn.php";
if(empty($_COOKIE['type']))
{
echo "<script language=JavaScript>
<!--
//Disable right click script III- By Renigade (renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com
var message=\"\";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function(\"return false\")
// -->
</script>";
}
?>
<script>
function precheck(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("srcHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/presearch.php?q="+str,true);
xmlhttp.send();
}
</script>
<script>
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("search");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Search box not completed");
// dialog message
var alertMsg = "OOPS!\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<?php
$page= isset($_GET['page']) ? $_GET['page'] : null;
$menu= isset($_GET['menu']) ? $_GET['menu'] : null;
function getPage()
{
$thispage="includes/".$_GET['page'].".inc";
if (file_exists($thispage))
{
include $thispage;
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
}
}
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
if (file_exists($thismenu))
{
include $thismenu;
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
}
}
?>It's only while using PDO that it's failing.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: New to PDO: basic script failing. Including ORDER BY...
And there it is; scoping issue. $pdo does not exist within the scope of your getMenu() function. Pass it in as an argument.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
Sorry you have lost me. I've no idea how to do that, as never had to.
I'm not passing any variable through, I'm just querying it generally.
On another menu file, I will be passing thru a variable via $menu to query it specifically.
So don't know why I need to put PDO into the menu. Sorry.
I'm not passing any variable through, I'm just querying it generally.
On another menu file, I will be passing thru a variable via $menu to query it specifically.
So don't know why I need to put PDO into the menu. Sorry.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: New to PDO: basic script failing. Including ORDER BY...
I'd recommend giving this a read if you're unclear on variable scope: http://php.net/manual/en/language.variables.scope.php
Your $pdo variable is defined in the global scope, outside the scope of that function. Within getMenu(), $pdo is undefined. Simply pass the object in as an argument like so:
Then call it thus:
The initial PDO is a type hint; it tells the function to expect the variable $pdo to be an object of type PDO. The $pdo in the function signature sets the variable's name within the function itself.
Your $pdo variable is defined in the global scope, outside the scope of that function. Within getMenu(), $pdo is undefined. Simply pass the object in as an argument like so:
Code: Select all
function getMenu(PDO $pdo) {
// Same function logic here
}Code: Select all
getMenu($pdo);-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: New to PDO: basic script failing. Including ORDER BY...
Here lies a problem then.
I was told that I could use PDO and the old mysql_ at the same time, until I have the site full PDO converted.
From this, seems I cannot! Because PDO is in the script there.
All of that said, I am now getting this error:
[text]object(PDOStatement)#2 (1) { ["queryString"]=> string(44) "SELECT email FROM admin WHERE type = 'admin'" } [/text]
I was told that I could use PDO and the old mysql_ at the same time, until I have the site full PDO converted.
From this, seems I cannot! Because PDO is in the script there.
All of that said, I am now getting this error:
[text]object(PDOStatement)#2 (1) { ["queryString"]=> string(44) "SELECT email FROM admin WHERE type = 'admin'" } [/text]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: New to PDO: basic script failing. Including ORDER BY...
You can use both. You can refactor piecemeal. If you're at the stage where you're refactoring the menu, then you'll also need to update any code it relies on. That's how refactoring works.
What you're getting below doesn't look like an error, it looks like the output of var_dump.
What you're getting below doesn't look like an error, it looks like the output of var_dump.