Page 2 of 2
Re: Can't access db on godaddy
Posted: Fri Mar 13, 2009 11:43 pm
by sleepydad
So does this mean that I cannot write my script as object oriented as I've been learning, and have to learn procedural instead? Or, should I theoretically be able to just drop the "i' from mysqli and be on my way?
I'm hoping I can salvage my script and most importantly the knowledge that I've gained over the past few months studying php as object oriented.
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 12:08 am
by Benjamin
Well we first need to verify that is the problem.
Put this at the top of the page that is giving you the blank page:
Code: Select all
error_reporting(E_ALL);
ini_set("display_errors", 1);
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 12:36 am
by sleepydad
Did that. Here's what I got ...
Notice: Undefined index: doWhat in /home/content/s/l/e/sleepydad/html/players.php on line 7
Notice: Undefined index: name in /home/content/s/l/e/sleepydad/html/players.php on line 8
Notice: Undefined index: time in /home/content/s/l/e/sleepydad/html/players.php on line 9
Notice: Undefined index: day in /home/content/s/l/e/sleepydad/html/players.php on line 10
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 12:41 am
by Benjamin
So this is the page that is blank, and you are only getting notices? You may have to post your code. Is the content on this page rendered from the database?
EDIT: You know what, I forgot you had an @ sign in front of your database call. That's supressing the error. Remote the @ sign please.
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 12:51 am
by sleepydad
Here is my code
Code: Select all
// variables are sent from Flash .swf embedded in HTML
$index=null;
$doWhat=$_POST['doWhat'];
$name=$_POST['name'];
$time=$_POST['time'];
$day=$_POST['day'];
$doWhat=trim($doWhat);
$name=trim($name);
$time=trim($time);
$day=trim($day);
if(!get_magic_quotes_gpc()) {
$doWhat=addslashes($doWhat);
$name=addslashes($name);
$time=addslashes($time);
$day=addslashes($day);
}
@ $db=new mysqli('xxmysqlxx.secureserver.net', 'xxxxx', 'xxxxx', 'xxxx');
if(mysqli_connect_errno()) {
echo 'Error connecting to database. Please try back later.';
}
if ($doWhat=="clear") {
////// admin or clear day after play
$query="truncate table `players`";
$result=$db->query($query);
makeXML();
}
elseif ($doWhat=="add") {
$query="select * from `players`";
$result=$db->query($query);
$numRows=$result->num_rows;
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
if($name==$row['name']) {
$dupe=true;
$useIndex=$row['index'];
break;
}
}
if($dupe) {
$query="delete from `players` where `index` = {$useIndex}";
$result=$db->query($query);
}
////// add new player to roster
$query="insert into `players` values ('".$name."', '".$time."', '".$day."', '".$index."')";
$result=$db->query($query);
makeXML();
}
else {
///// remove
$dupe=false;
$query="select * from `players`";
$result=$db->query($query);
$numRows=$result->num_rows;
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
if($name==$row['name']) {
$dupe=true;
$useIndex=$row['index'];
break;
}
}
if($dupe) {
$query="delete from `players` where `index` = {$useIndex}";
$result=$db->query($query);
}
makeXML();
}
function makeXML() {
////// xml for flash read
@ $db=new mysqli('xxxmysqlxx.secureserver.net', 'xxxxx', 'xxxxx, 'xxxxx');
$query="select * from players";
$result=$db->query($query);
$numRows=$result->num_rows;
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n";
echo "<roster>\n\n";
echo "<names>\n";
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
echo "<name>".$row['name']."</name>\n";
}
echo "</names>";
echo "\n\n";
echo "<days>\n";
$query="select * from players";
$result=$db->query($query);
$numRows=$result->num_rows;
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
echo "<day>".$row['day']."</day>\n";
}
echo "</days>";
echo "\n\n";
echo "<times>\n";
$query="select * from players";
$result=$db->query($query);
$numRows=$result->num_rows;
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
echo "<time>".$row['time']."</time>\n";
}
echo "</times>";
echo "\n\n</roster>";
}
$db->close();
This works perfectly when tested locally through MAMP.
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 12:56 am
by sleepydad
With '@' removed, I get the following:
Notice: Undefined index: doWhat in /home/content/s/l/e/sleepydad/html/players.php on line 7
Notice: Undefined index: name in /home/content/s/l/e/sleepydad/html/players.php on line 8
Notice: Undefined index: time in /home/content/s/l/e/sleepydad/html/players.php on line 9
Notice: Undefined index: day in /home/content/s/l/e/sleepydad/html/players.php on line 10
Fatal error: Cannot instantiate non-existent class: mysqli in /home/content/s/l/e/sleepydad/html/players.php on line 25
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 1:21 am
by Benjamin
Ok. Tell godaddy you need a server that supports MySQLi. I'd certainly switch hosts before I edited all my code.
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 10:41 am
by sleepydad
Thanks again for your assistance astions. You're more tenacious than godaddy's support! I have an email into godaddy to see if they offer mysqli support, but in the event that they don't can you or anyone out there recommend a reliable host that does? I don't need a ton of space or a bunch of bells and whistles for this site. I do need a host that can support php 5 and mysqli, is affordable (godaddy is about $54 annually for hosting), and offers at least decent tech support.
Anyone??
Thanks again to all for pulling the all-nighter with me last night!
sleepydad
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 4:56 pm
by califdon
You're emailing godaddy? No wonder you are dissatisfied with their response. A 5-minute call to Phoenix will almost certainly clarify the whole situation, based on my 2 years of experience with them. Just as a personal opinion, if it is a matter of switching web hosts in order to get mysqli (which I'm now sure is your problem), I wouldn't do it for that reason. I'm not minimizing the value of OO and mysqli, but in my opinion it's like any library--useful in many cases, but certainly not a critical requirement unless you're contracting with the federal gov't or something. Just one perspective.
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 5:18 pm
by sleepydad
Hi again Jack, and thanks for the input. I'm coming from this angle, weak argument though it may be:
I bought this 893 page book on PHP and mySQL. I'm about 3/4 through it, and have been following lessons specifically geared toward OO. I asked many people which route to go, procedural vs OO, and got an almost 50-50 reply. My cousin who is an engineer was the one who swayed me in the end based on him interviewing me and questioning what exactly I envision doing with databases in future projects. Bottom line is that I'm up to my elbows in OO language study and I don't want to jump back to start and re-learn this stuff again as procedural. Lazy? Maybe, but I'm super busy and don't have time to reinvent the wheel. Hope that doesn't sound stand off'ish. Not at all my intent. Just trying to explain where my head's at.
So who or what is this Phoenix that you refer to? A person at godaddy, or is this a host that I should contact?
Thanks to all who've stuck with me on this the last couple of days. I think I'm seeing some light at the end of the proverbial tunnel!
sleepydad
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 6:22 pm
by califdon
[To clarify, my name is Don, but I can easily see why people sometimes mistake the caption for my avatar for my name. Not important. As long as you get it right on the check you send me!]
Sorry for the misunderstanding--Phoenix, Arizona is where Godaddy.com is located. They don't provide a toll-free telephone number, so their location is pertinent, depending on where you're calling from. For me, it's a free call from my mobile phone during off-peak hours, or I burn a few of my 200 minutes per month quota, which I almost never use anyway. I wouldn't dream of emailing them!
I'm not the best person to discuss mysqli or OO, in general. I have no experience using mysqli and very little OO experience. I would encourage your study and use of OO, but that doesn't mean that you have to use mysqli! To the best of my knowledge, mysqli is a useful, popular library for abstracting mysql operations, but it is certainly not the only one, and you can even roll your own, without relying on anything beyond what I know that godaddy supports. It just happens that mysqli has been packaged as a PHP library--at least, that's my understanding. If I'm wrong, I'm sure someone here will correct me.
What I'm saying is that, in the event that you can't get mysqli support from godaddy, there are many other OO options. Some people like godaddy (I do) and some people don't, but if they meet your needs in other respects, I don't see their possible lack of support for mysqli to be nearly a sufficient reason to go to the bother of setting up another hosting service, learning all their idiosyncrasies, forfeiting what you've already spent on godaddy, and very likely paying more for your hosting service. The very few lower cost hosting services that I know of have absolutely dreadful reputations.
I am on a mailing list that sends me a daily average of two open source PHP class announcements (written by amateurs all over the world), and I would estimate that at least 25% of them are someone else's idea of an OO database abstraction class. Probably most of them are either specialized or just plain awful, but my point is that you are certainly not limited to mysqli as the only way you can learn and use OO with PHP and mysql!
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 7:25 pm
by sleepydad
Nice to meet you, Don. You aren't going to believe this, but my name's Don too!
Thanks for the input (once again). Fortunately I'm at a point where this site that I want to use the mysqli is not hosted by anyone yet. I've been testing it on some web space that I already own through godaddy. I have yet to purchase the domain name and hosting package for this project that I'm working on. All in all, godaddy's taken care of me pretty well. I'm a web designer by trade, specializing in Flash actionscript driven sites, and moonlight out of my home when I'm not at my real job. I automatically recommend godaddy to my clients, and have sent them a handful of new business over the past few months. I've tried a few other hosts with mixed results, but godaddy is fairly consistent so I'm comfortable using and recommending them overall. I'm trying to crack the 'designer' mold and get more into the backend stuff because everyone these days learns HTML and hangs a shingle claiming to be a designer. I need to get more into the programming side and put myself above the competition. Fortunately I have a pretty solid grasp of actionscript (OO by the way) so it's served as a pretty good springboard into the world of PHP. Database stuff on the other hand is completely new to me. Some of the terminology that you used is still Greek to me, but give me a couple more months and I'm sure it'll make sense.
Don (aka sleepydad)
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 8:31 pm
by califdon
Sounds like you're off to a good start to add to your skillset. Having taught database classes in college for nearly 10 years before retiring, as well as developing databases with at least 4 or 5 different database engines, both for profit and as a volunteer, I think I can give you advice about that particular area. The most valuable thing you can learn is the theory behind relational databases. Out of every 100 people that SAY they know how to structure a database schema, probably less than a dozen actually DO. And I can assure you that the most common database issue that arises here in the forums is that someone THINKS they have a problem with coding, but the REAL problem is that the structure of their data is wrong and they don't realize it. In fact, sometimes they will get into heated arguments with some of us, trying to justify why they are doing something that we know full well is in violation of data normalization rules or some similar problem.
So while you're learning about PHP and mysql functions, I urge you to spend some time studying how data must be stored, in order to guarantee that you will be able to extract
information from your database. There are hard-and-fast rules about how tables must be structured, despite all the posts you will see here that make it sound like it's a matter of preference. I wrote a 7-page tutorial on Relational Database Principles for another forum, that might be helpful to you. It's at
http://forums.aspfree.com/microsoft-acc ... 08217.html. And there are lots of other tutorials (none as good as mine, of course, as I'm sure you'll agree

). The important thing is to understand that the front-end analysis of your data structure will save you untold hours/days/weeks of thrashing around in code later, frustrating yourself because you can't figure out how to get the data out in the form you need it.
Relational databases are simply
not intuitive and it requires forming new concepts. By starting out learning about them, you'll be way ahead of the crowd.
Good luck and if I can help you with details later, feel free to ask.
Re: Can't access db on godaddy
Posted: Sat Mar 14, 2009 8:33 pm
by Benjamin
Cheers
