database querying question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

database querying question

Post by m3rajk »

ok. i'm about to implement a dabase and enter the next stage of testing a site i'm making.


i have aquestion before i do ... when i connect to the mysql database, if the user can only use one databse, do i need to select a db orr is it automatically selected???

thanx in advance
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

try it <grin>
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Yes, you do:

$conn = mysql_connect("localhost","userid","pass") or die ("Cannot Connect to Database!");
$db = mysql_select_db("MyDB", $conn) or die ("Cannot Connect to Database");

Otherwise the DBMS will not know!

Phil J.
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

Some times computers are not logical....
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

thanx fractal. i figured as much but wasn't sure.here's a followup, for one of the dbs i wanna enter the current date in datetimeformat when an entry is made, would that work right if i passed it NOW() as the value?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

m3rajk wrote:for one of the dbs i wanna enter the current date in datetimeformat when an entry is made, would that work right if i passed it NOW() as the value?
Have you tried it?

Mac
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

not yet, every time i think i'm ready to make the database one of the ones i;m working with decides there needs to be a new feild, so i then give them another day to figureout if we've missed something...result: i'm preparing the php for the db, but am holding off on making the db since some tables (specifically the main one) keeps getting modified
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

> i wanna enter the current date in datetimeformat when an entry is made, would that work right if i passed it NOW() as the value?

Thats one way. The other is to make your field a timestamp and it will automatically do that. A note, though, timestamp auto-updates EVERY time you edit the record, (I use it for last-updated type fields)
So if you want the date the record was entered, perhaps try setting the default in the field definition as NOW(). I am FAIRLY certain you can use a function as a default value and eliminate the need to bother with it in your code.

Been lazy, always will be lazy.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

this is for comments. they wont be updateable. but that's good to know because i plan to make a forums later from scratch to accompany the profiles i'm making.

backstory: i keep gettng told i don't have the db/php experience needed to get jobs, a friend wants her own rateme site and is great with graphics. we're teaming up. we're deciding layout and functionality together, but she she doesn't even knwo html i'm doing ALL the coding and leaving ALL the graphics to her. so it'll show off db/php abilities. we're adding some features not on other rateme sites so that we can have a hook of being more than a simple rateme site...
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

>backstory: i keep gettng told i don't have the db/php experience needed to get jobs

Whatever. I got my experience from jobs. I got them. I compensated for my lack of knowledge, and now I have the experience. Don't let peoples opinions dissuade you. They are probably just trying to limit the competition anyway.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

no. that's what i'm hearing from employers when they tell me that i didn't get the job i applied for advertised as entry level (the fact i got the same responses when looking for internships all four years of college are what lead to my signature)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

down with corporations!
Post Reply