spdwrench Posted October 28, 2007 Share Posted October 28, 2007 Hello I am a web developer and new php programmer... a girl I know needs help with a project.. she need to write a python script that can search a database with a student database...... with subject / class / section / students... could someone please point me to some sample code to look at to perform a simalar result? also what type of database is generally used ?? thanks paul Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/ Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 You / she might want to take a look at the MySQLdb module for Python. Its pretty straight forward to use... #!/usr/bin/python import MySQLdb db = MySQLdb.connect(host="localhost", user="foo", passwd="",db="foodb") cursor = db.cursor() sql = "SELECT subject class section students FROM tbl" cursor.execute(sql) rows = int(cursor.rowcount) if rows > 0: for x in range(0,rows): row = cursor.fetchone() print row[0],row[1],row[2],row[3] Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-379594 Share on other sites More sharing options...
spdwrench Posted October 29, 2007 Author Share Posted October 29, 2007 I have only used mysql through php on my linux server... I have the python and mysql link you gave me running on windows... do you know how to initialize the database and what should the connection read?? is it still localhost??? how to I set this database up fro connection... when I do it for my webbased stuff I just use plesk... please help Paul Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-380775 Share on other sites More sharing options...
trq Posted October 30, 2007 Share Posted October 30, 2007 I have the python and mysql link you gave me running on windows... have you installed MySQL on this machine? do you know how to initialize the database Type... mysql on the command line or use phpmyadmin if your not up for it. and what should the connection read?? is it still localhost??? localhost will (should) work if the MySql server is installed and configured on the local machine. Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-380809 Share on other sites More sharing options...
spdwrench Posted October 30, 2007 Author Share Posted October 30, 2007 I installed mysql for python it seemed to install fine... so I think what I need to do is initialize the databse (create) I just have never used python can I create the database withing the code? or do I need to use a phpadmin or comand line to create my database...?? thanks for your help I have not spent alot of time but could not find much. I am looking into this after 11 hour workdays at my job... sorry to be such a pain. Paul Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-381037 Share on other sites More sharing options...
trq Posted October 30, 2007 Share Posted October 30, 2007 I installed mysql for python That doesn't meen MySQL is installed. Go to the command line. (start->run->cmd) and type... mysql --version what do you get? can I create the database withing the code? Of course you could, just execute the valid query. Its much the same as php. Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-381073 Share on other sites More sharing options...
spdwrench Posted October 30, 2007 Author Share Posted October 30, 2007 I get windows cannot find 'mysql' make sure you typed the name correctly , and try again Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-381515 Share on other sites More sharing options...
trq Posted October 30, 2007 Share Posted October 30, 2007 Then you have not got MySQL installed. Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-381549 Share on other sites More sharing options...
spdwrench Posted October 30, 2007 Author Share Posted October 30, 2007 ok I had some time to do a little digging she told me she wants the script as simple as possible I found python to have a built in database using the following code import anydbm db = anydbm.open("database", "c") db["1"] = "one" db["2"] = "two" db["3"] = "three" db.close() db = anydbm.open("database", "r") for key in db.keys(): print repr(key), repr(db[key]) this code produces result: '2' 'two' '1' 'one' '3' 'three' now any idea on how I would make a searchable database out of this? with subject .... class... section.... student....?? give me just a little direction if you could... I would prefer to use this simple method because they are not really expecting much from this project.... thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-381571 Share on other sites More sharing options...
trq Posted October 31, 2007 Share Posted October 31, 2007 now any idea on how I would make a searchable database out of this? Ive never used anydbm before but it does'nt look like it supports sql. This could makes things more difficult than need be. Maybe take a look at pySqlite if you dont want to go the route of installing MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-381582 Share on other sites More sharing options...
Daniel0 Posted November 6, 2007 Share Posted November 6, 2007 Then you have not got MySQL installed. Actually the path to the MySQL binaries is not added to PATH when installing. You have to do it manually or check a box in a configuration wizard which is run after installing it. Quote Link to comment https://forums.phpfreaks.com/topic/75056-python-simple-script-need-help/#findComment-386051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.