Jump to content
Larry Ullman's Book Forums

Connecting To A Database


Recommended Posts

Hello larry, et al-

 

Before I kill myself out of exasperation, I thought I would try this forum. Page 336 specifies how to connect to a mysql database. I have run the script:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

 

<body>

 

<?php

 

if ($dbc = mysql_connect('localhost', 'superf12_duane', '********';)) {

 

print '<p>connected...</p>';

 

mysql_close($dbc);

 

} else {

 

print '<p>disconnect</p>';

 

}

 

?>

 

</body>

</html>

 

I only get:

connected...

'; mysql_close($dbc); } else { print '

notconnected

 

'; } ?>

 

In addition, I have chatted with the hosting company, they confirm no established conections were made. I gone to many various forums and followed the advice from others having difficulties connecting. Nothing seems to be working....

 

Can someone tell me what mistake I have made?

 

thanks

doug

I get

Link to comment
Share on other sites

Larry-

 

Just in case you are thinking I am too lazy to type out the whole script (which I have done repeatedly), here is the full version:

 

<body>

 

<?php

 

if ($dbc = mysql_connect('localhost', 'superf12_duane', '********')) {

 

print '<p>Successfully connected to MySQL!</p>';

 

mysql_close($dbc);

 

} else {

 

print '<p style="color: red;">Could not connect to MySQL.</p>';

 

}

 

?>

 

</body>>

</html>

 

 

And here is what I get:

 

Successfully connected to MySQL!

'; mysql_close($dbc); } else { print '

Could not connect to MySQL.

 

'; } ?

Link to comment
Share on other sites

...by the way, it seems odd to me that in your script no database has been specified.... (though I have tried adding it is various other scripts)

 

my guess is this is the ultimate issue....however, I am getting no error message whatsoever, even when I mis-spell the username....

 

so it seems to me the PHP itself is not executing...your script specifically uses a .HTML format (as opposed to .php) so that must not be it...

 

I am running this through my hosted account (inmotion), so the PHP is going through a server to be executed....

 

the database itself is good, I have added records to it via phpmyadmin

 

again, why no error message? unless PHP is not exucuting?

Link to comment
Share on other sites

Hello Larry-

 

To answer your question as to the source of my confusion reagarding the extension of the script.

 

I think my confusion was over the idea that the script that "handles" the PHP has a "PHP'ish" header unlike an HTML page.

 

Yes, I realize we were doing a script that was self-executing, but my mind had not caught up with the distinction....

 

I still thinking, as you previously trained me to, to think HTML page first, PHP next.....

 

Everything I know about PHP i learned from Larry Ullman. I am new to this....unlike others I see in your forums, I am not a student with a teacher using this book as the rate of a chapter a week with class and discussion....I am blowing through 50 pages at a time, trying to quickly learn PHP and build a dynamic website....

 

If I could be candid....for people like me, who are trying to make a living at the same time we are trying to learn, you send us on many wild goose chases... for example after going through all the time and trouble to learn how to store data in files using PHP, I realized that really is ridiculous with MySQL being the more starndard choice....so why not put that stuff in a "by the way" sidebar...rather than pulling us all through excercises that are not likely to be useful to us on a day to day basis.

 

Another example of that wild goose chase is the PHP tutorial on creating databases/tables with PHP- that was properly sidebar material--- most of us will use PHPMyADmin.

 

So, to summarize, I lover your writing style, I love your book. I am not saying you are not fabulous at what you have given me (essentially your life's work for less than forty bucks!~).... I am jsut saying that you should think about our time management issues and not have us try to learn everything....

 

thanks

doug

Link to comment
Share on other sites

Doug you are very narrow sighted with some opinions. What if I want to back up for database records? Are you going to do this by hand or use php to back them up to text compressed text files? This is just one example. Not everyone uses databases, some people use csv files. What if the said person doesn't have or use phpMyadmin?

 

What's useful you on a day by day basis, doesn't mean its the same for the next person. And to truly take advantage of PHP you need to be aware of its capabilities.

Link to comment
Share on other sites

Doug you are very narrow sighted with some opinions. What if I want to back up for database records? Are you going to do this by hand or use php to back them up to text compressed text files? This is just one example. Not everyone uses databases, some people use csv files. What if the said person doesn't have or use phpMyadmin?

 

What's useful you on a day by day basis, doesn't mean its the same for the next person. And to truly take advantage of PHP you need to be aware of its capabilities.

 

Whoa! No need to get nasty. No need for personal attacks. Of course I have some opinions? Don't we all. Narrow sighted? When it comes to databases, perhaps, since that is what I do for a living...putting them on the internet is what I am trying to learn how to do....

 

By the way, PHPMyAdmin is a free utility that practically every hosting company in the world offers for free as a way to access back-end databases...It is the standard. My point here was that using php to create databases and tables is more elegant, secure, and efficient. As your knowledge of databases grows, perhaps you will shoot me an email with an apology for your personal attack about something your really dont knowmuch about.

Link to comment
Share on other sites

Firstly Doug I'm not being nasty, I genuinely think your not allowing your self to see into further possibilities within the language.

Secondly, you come on to the writers forum and describe parts of his writing a 'wild goose chases' and 'ridiculous' for trying to teach you more about the subject. That's frankly just rude.

Do you expect the whole book to tailor to your specific needs?

I'm happy with my knowledge of databases thank you, but I'm always trying to expand on anything web related. I'm also well aware of phpmyadmin thank you.

And I don't feel I was nasty I was merely pointing out that you are not allowing yourself to expand your knowledge of php. You may feel that my response was nasty, I don't. You may not think that your tone initially was some what rude, I do.

The forum is meant to help people and this topic now doesn't help people. I'm sure that Larry values all feedback, but perhaps this isn't the place for your feedback as there are other mediums in which to do so. And I personally found your feedback quite rude.

Link to comment
Share on other sites

Jonathan-

 

Here is what you are missing is your psychoanalysis of me. Larry, your mentor who you are protecting, and whose ego you are assuming was crushed by my thoughtless, rude, narrow-minded response, sent me an email ASKING for information about my interaction with the book.

 

So here is the thing Jonathan: critique is good, honest (sometimes brutal) critique is good. The reason is because true critique is a window into a person's emotional reaction to your work. I serve Larry better, in his professional work, by giving him my absolute, honest, no-holds-barred, opinions of his work. Then he can ponder it, assess it, decide I am a lunatic and ignore me, or decide there may be a breadcrumb or two of good feedback that he can incorporate into his next book. If you will note, I did not attack Larry in any way, in fact I complimented him and let him know that I considered the price of the book a pittance in exchange for him sharing the results of his life's work with me.

 

Now let's talk about you. You do not serve Larry well. Larry is actively trying to grow his forums. He is actively trying to encourage participation. You, in your posts to me, attack me for giving larry the honest reaction he has asked for. Think about it Jonathan, you attacked me for simply stating what I thought. That makes you part of the "thought police" which creates a chilling effect on honest interaction. Now people will be less inclined to participate in the forum becasue the "thought police" will attack them. Now you have robbed your mentor, Larry, of the honest criticism that he is actively trying to solicit.

 

My point with Larry was valid, diverting readers to sidebars for secondary information gives the readers a choice to plow through a chunk of text and practice, rather than forcing us all to plow through everything, only to have him say, "ok, so what you just spent two hours on, don't worry about that anymmore, becasue you're likely to use PHPMyAdmin anyway. The reason he plowed through it was becasue most of his readers are not up for stopping his book to figuring out how to use PHPMyAdmin....so he can keep the flow of his book going by retaining contrtol of the reader and giving them a total solution rather than divert to PHPMyAadmin.

 

Jonathan, another thing, I believe it was you who posted to Larry that you had left a good review for him on Amazon...like a puppy licking his master's feet. Again, you identify yourself at that point as a minnion- people tend to ignore minnions, preferring instead to interact with real people giving real thoughts and ideas.

 

You are correct, there are many many occasions when using PHP would be the better solution in interacting with data rather than going through PHP. I did not state otherwise in my misguided post. I stated that creating a database or tables is more elegantly and efficiently done through PHP, IN MY OPINION.

 

Some day you will use PHPMyAdmin and you will realize that Iam right about this. Or not. Either way, it is me who has taken the higher ground in this forum by providing larry with my honest opinons, constructive critique that he asked for, and not attacking him personally.

 

You attacked me for my personal opinions. Yuou were wrong. You owe me, Larry and all of the readers of this forum an apology. I am not going to waste any more time with you. And I am not coming back to this forum ever again. There, your job is done, you have chased away the nasty person who had the audacity to say something you did not like.

Link to comment
Share on other sites

Doug, you are clearly a sensitive person. If I had of known that my innocent, legitimate response would have caused this much of a respone, then I would not have bothered.

 

I simply tried to point of something you may not have thought of, hence why i thought you were narrow sighted in your opinions of PHP. Not Larry's writing as you may have thought. Perhaps had I have worded it as " I think you have not thought of the possibility of.... then maybe you wouldn't have taken such offence. Perhaps you have taken this to heart and as a peronal attack. I did in turn find your tone somewhat poorly constructed.

 

You stated

for example after going through all the time and trouble to learn how to store data in files using PHP...

 

I simply pointed out that a valid example of a situation where you would want to write data to a file using php was backing up a database to a text file.

 

I work with PHPMyAdmin every day, it's my job!! But did you know that you can't use it for Postgre?? (or at least you couldn't)? This again is all I meant by what I consider to be an oversight on you part.

 

I probaby did write Larry a good review on Amazon... Because I have read quite a few books on various languages and I found Larry's book to be very good. I also in turn gave quite in depth feedback regarding his up coming PHP and MYSQL book.

 

Think about it Jonathan, you attacked me for simply stating what I thought.

 

I have not at ANY point tried to attack you. As already explained. You may notice that I am quite active in the foums, where the majority of time I try to help people where I can. I obviously have my own questions I ask too as I am constantly trying to develop myself.

 

You accuse me of being the "thought police" an that people can't raise their own thoughts. Surely that is the most hypocritical statement made in this entire series of threads?? As you have taken huge offence for my opinion that I thought you were being narrow sighted with regards to PHP.(Again, perhaps that could have been worded better as mentioned earlier)

 

I refuse to get involved in any tit for tat as I stated earlier this forum is for helping people. Which is all I tried to point out before.

 

If you wish never to visit the forum again then that is your loss i'm affraid.

Link to comment
Share on other sites

... for example after going through all the time and trouble to learn how to store data in files using PHP, I realized that really is ridiculous with MySQL being the more starndard choice ...

I would have to disagree with this particular example ... writing to files is a very useful technique which you will likely eventually need to know. I have used it to write text files containing registration information to a folder (even though the data was also stored in a database) so that these files can be read and parsed later by an automated billing system. And I have created HTML reports out of database information, then had someone say "Hey, that's great! But can I have it in spreadsheet format?" So I write to a CSV text file and force it to download.

 

The particular book that you're posting about (which I don't have) is for someone completely new to PHP, and goes at a slower pace. You might have been better served by Larry's "PHP and MySQL for Dynamic Websites" books, which jump into MySQL fairly early on in the book.

Link to comment
Share on other sites

 Share

×
×
  • Create New...