Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Chris
Isaak Malik wrote:
> Because then the connection resource isn't stored in the $link variable
> and you will be able to use the mysql functions without passing that
> variable to each function.

RTM again.

The link parameter is completely optional.

If you don't specify it, it uses the last connection created.

I can do this and it's perfectly valid:

$link = mysql_connect($server, $user, $pass);
if (!$link) {
  die ("Unable to connect to the database server");
}

$db_selected = mysql_select_db($databasename);
if (!$db_selected) {
  die("Unable to connect to the database $databasename");
}

$result = mysql_query("select 1");

-- 
Postgresql & php tutorials
http://www.designmagick.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Isaak Malik
To Evert:

4. I am posting some of my code to compare. Module "carmade.php" works v.s.
"login.php" which does not. Also, I am posting my "database.php" which is
establishing the connection and is included in every page through
"layout.php"->"common.php"->"database.php".

To bateivan:

I can only guess that the database.php file isn't correctly loaded via
layout.php, did you already try to include database.php into the module in
which it wasn't working? If so and it works then the issue is probably
caused by incorrectly including that file, otherwise it has to be something
else...

And register_globals allows you to use short variables for super global
arrays. Ex: $name instead of $_POST['name'], etc.


On Wed, Jun 18, 2008 at 9:47 PM, Evert Lammerts <[EMAIL PROTECTED]>
wrote:

> Pastebin works lots better when you're posting code: www.pastebin.com
>
> I don't see your database.php included in both of these modules. Where
> do you include it?
>
> EVert
>
> On Wed, Jun 18, 2008 at 9:38 PM, bateivan <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > To answer these qwestions:
> > 1. I am using "include" in my code.
> > 2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
> > variable. I can just include this line before mysql_query function and it
> > works even without entering into mysql_query the "$link" variable. (Like
> the
> > connection is waking up).
> > 3.My php.ini register_globals is off as suggested for new versions of PHP
> > but include file should work instead according to the manual.
> > 4. I am posting some of my code to compare. Module "carmade.php" works
> v.s.
> > "login.php" which does not. Also, I am posting my "database.php" which is
> > establishing the connection and is included in every page through
> > "layout.php"->"common.php"->"database.php".
> >
> > carmade.php:
> >  > include $_SERVER['DOCUMENT_ROOT'].
> >'/layout.php';
> >
> > // Quick Login session check
> > login_check();
> >
> > switch($_REQUEST['req']){
> >   // Insert Case
> >   case "create_carmade":
> > myheader("Добавяне на автомобилни марки в списъка");
> >
> > // Double check form posted values are there
> > // before performing INSERT query
> > if(!$_POST['car_descr']){
> > echo 'Липсва информациятя от формата!'.
> > 'Моля, използвайте бутона'.
> > 'Назад и въведете данните отново!';
> >  footer();
> > exit();
> > }
> >
> > // Insert Query
> > $sql = mysql_query("INSERT INTO carmade
> > (car_descr)
> > VALUES('{$_POST['car_descr']}')");
> >
> > // Insert query results
> > if(!$sql){
> > echo "Грешка при въвеждане на данните:".mysql_error();
> > } else {
> >
> > echo 'Марката "'.$_POST['car_descr'].
> > '"е въведенас номер:'.mysql_insert_id();
> > echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
> >'въведете друга марка? ';
> > }
> >   break;
> >
> >   // Create car made form case
> >   case "new_carmade":
> >  myheader("Въвеждане на нова автомобилна марка");
> >  include $_SERVER['DOCUMENT_ROOT'].
> >  '/html/forms/carmade_insert.html';
> >  footer();
> >   break;
> >
> >   default:
> >  myheader("Администриране на списъка с автомобилните марки");
> >  include $_SERVER['DOCUMENT_ROOT'].
> >  '/html/carmade_admin.html';
> >  footer();
> >   break;
> >
> > }
> > ?>
> >
> > login.php:
> >  > include $_SERVER['DOCUMENT_ROOT'].
> >'/layout.php';
> >
> >
> > switch($_REQUEST['req']){
> >
> > case "validate":
> >
> >   $validate = mysql_query("SELECT * FROM members
> >   WHERE username = '{$_POST['username']}'
> >   AND password = md5('{$_POST['password']}')"
> >   );
> >
> >   $num_rows = mysql_num_rows($validate);
> >
> >   if($num_rows == 1){
> >  while($row = mysql_fetch_assoc($validate)){
> > $_SESSION['login'] = true;
> > $_SESSION['userid'] = $row['member_id'];
> > $_SESSION['first_name'] = $row['first_name'];
> > $_SESSION['last_name']  = $row['last_name'];
> > $_SESSION['email_address'] = $row['email_address'];
> >
> > if($row['admin_access'] == 1){
> >$_SESSION['admin_access'] = true;
> > }
> > $login_time = mysql_query("UPDATE members
> >   SET last_login=now()
> >   WHERE id='{$row['id']}'");
> >   }
> >   header("Location: /loggedin.php");
> >   } else {
> >  myheader("Входът в административната зона е неуспешен!");
> >  echo 'Входът в страницата не е успешен!';
> >  echo 'Проверете потребителското си '.
> >   'име и паролата си и опитайте пак или се '.
> >   'обадете на администратора.';
> >  footer();
> >   }
> > break;
> >
> > default:
> >   myheader("Вход!");
> >  include $_SERVER['DOCUME

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Evert Lammerts
Pastebin works lots better when you're posting code: www.pastebin.com

I don't see your database.php included in both of these modules. Where
do you include it?

EVert

On Wed, Jun 18, 2008 at 9:38 PM, bateivan <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> To answer these qwestions:
> 1. I am using "include" in my code.
> 2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
> variable. I can just include this line before mysql_query function and it
> works even without entering into mysql_query the "$link" variable. (Like the
> connection is waking up).
> 3.My php.ini register_globals is off as suggested for new versions of PHP
> but include file should work instead according to the manual.
> 4. I am posting some of my code to compare. Module "carmade.php" works v.s.
> "login.php" which does not. Also, I am posting my "database.php" which is
> establishing the connection and is included in every page through
> "layout.php"->"common.php"->"database.php".
>
> carmade.php:
>  include $_SERVER['DOCUMENT_ROOT'].
>'/layout.php';
>
> // Quick Login session check
> login_check();
>
> switch($_REQUEST['req']){
>   // Insert Case
>   case "create_carmade":
> myheader("Добавяне на автомобилни марки в списъка");
>
> // Double check form posted values are there
> // before performing INSERT query
> if(!$_POST['car_descr']){
> echo 'Липсва информациятя от формата!'.
> 'Моля, използвайте бутона'.
> 'Назад и въведете данните отново!';
>  footer();
> exit();
> }
>
> // Insert Query
> $sql = mysql_query("INSERT INTO carmade
> (car_descr)
> VALUES('{$_POST['car_descr']}')");
>
> // Insert query results
> if(!$sql){
> echo "Грешка при въвеждане на данните:".mysql_error();
> } else {
>
> echo 'Марката "'.$_POST['car_descr'].
> '"е въведенас номер:'.mysql_insert_id();
> echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
>'въведете друга марка? ';
> }
>   break;
>
>   // Create car made form case
>   case "new_carmade":
>  myheader("Въвеждане на нова автомобилна марка");
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/html/forms/carmade_insert.html';
>  footer();
>   break;
>
>   default:
>  myheader("Администриране на списъка с автомобилните марки");
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/html/carmade_admin.html';
>  footer();
>   break;
>
> }
> ?>
>
> login.php:
>  include $_SERVER['DOCUMENT_ROOT'].
>'/layout.php';
>
>
> switch($_REQUEST['req']){
>
> case "validate":
>
>   $validate = mysql_query("SELECT * FROM members
>   WHERE username = '{$_POST['username']}'
>   AND password = md5('{$_POST['password']}')"
>   );
>
>   $num_rows = mysql_num_rows($validate);
>
>   if($num_rows == 1){
>  while($row = mysql_fetch_assoc($validate)){
> $_SESSION['login'] = true;
> $_SESSION['userid'] = $row['member_id'];
> $_SESSION['first_name'] = $row['first_name'];
> $_SESSION['last_name']  = $row['last_name'];
> $_SESSION['email_address'] = $row['email_address'];
>
> if($row['admin_access'] == 1){
>$_SESSION['admin_access'] = true;
> }
> $login_time = mysql_query("UPDATE members
>   SET last_login=now()
>   WHERE id='{$row['id']}'");
>   }
>   header("Location: /loggedin.php");
>   } else {
>  myheader("Входът в административната зона е неуспешен!");
>  echo 'Входът в страницата не е успешен!';
>  echo 'Проверете потребителското си '.
>   'име и паролата си и опитайте пак или се '.
>   'обадете на администратора.';
>  footer();
>   }
> break;
>
> default:
>   myheader("Вход!");
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/html/forms/login_form.html';
>   footer();
> break;
> }
> ?>
>
> database.php:
>  $link = mysql_pconnect('localhost','root','testing');
> $set = mysql_query('SET NAMES CP1251');
> $set = mysql_query('SET_COLLATION=CP1251_GENERAL_CI');
> mysql_select_db('samek_db', $link) or die(mysql_error());
>
> ?>
>
> common.php:
> 
> // Include Meta Content Class
> include $_SERVER['DOCUMENT_ROOT'].'/classes/clsMetaContent.php';
>
> // Include Email Class
> include $_SERVER['DOCUMENT_ROOT'].'/classes/clsEmail.php';
>
> // Include Database Connection File
> include $_SERVER['DOCUMENT_ROOT'].'/includes/database.php';
>
> // Include Session File
> include $_SERVER['DOCUMENT_ROOT'].'/includes/session.php';
>
> ?>
>
> Thank you for your help
>
>
> You're very welcome, I understand that you need a solution which allows you
> to keep using the connection this way.
>
> I doubt that your php.ini is the cause so I'll suggest the following:
>
> Try executing your MySQL queries by passing the $link variable to the
> function a

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread bateivan

Hello,

To answer these qwestions:
1. I am using "include" in my code.
2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
variable. I can just include this line before mysql_query function and it
works even without entering into mysql_query the "$link" variable. (Like the
connection is waking up).
3.My php.ini register_globals is off as suggested for new versions of PHP
but include file should work instead according to the manual.
4. I am posting some of my code to compare. Module "carmade.php" works v.s.
"login.php" which does not. Also, I am posting my "database.php" which is
establishing the connection and is included in every page through
"layout.php"->"common.php"->"database.php".

carmade.php:
Липсва информациятя от формата!'.
 'Моля, използвайте бутона'.
 'Назад и въведете данните отново!';
  footer();
 exit();
 }
 
 // Insert Query
 $sql = mysql_query("INSERT INTO carmade
 (car_descr)
 VALUES('{$_POST['car_descr']}')");
   
 // Insert query results  
 if(!$sql){
 echo "Грешка при въвеждане на данните:".mysql_error();
 } else {
 
 echo 'Марката "'.$_POST['car_descr'].
 '"е въведенас номер:'.mysql_insert_id();
 echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
'въведете друга марка? ';
 } 
   break;
   
   // Create car made form case
   case "new_carmade":
  myheader("Въвеждане на нова автомобилна марка");
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/forms/carmade_insert.html';
  footer();
   break;
   
   default:
  myheader("Администриране на списъка с автомобилните марки");
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/carmade_admin.html';
  footer();
   break;
   
}
?>

login.php:
Входът в страницата не е успешен!';
  echo 'Проверете потребителското си '.
   'име и паролата си и опитайте пак или се '.
   'обадете на администратора.';
  footer();
   }
break;

default:
   myheader("Вход!");
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/forms/login_form.html';
   footer();
break;
}
?>  

database.php:


common.php:


Thank you for your help


You're very welcome, I understand that you need a solution which allows you
to keep using the connection this way.

I doubt that your php.ini is the cause so I'll suggest the following:

Try executing your MySQL queries by passing the $link variable to the
function as the connection resource:

mysql_query("SELECT...", $link);

Something that also might cause it is that you use (include|require)_once
and that this module doesn't have access to the connection resource, if this
is the case change it into include|require and see if that solves your
issue. If not then could you please post some example code of your module if
possible so we can be more helpful?

Also be sure that you global $link; it in functions (I don't know if this
required since I didn't use it this way for a long while).

Could you also please answer to the list instead of directly to me as this
might also be informative for others.

-- 
View this message in context: 
http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17990192.html
Sent from the Php - Database mailing list archive at Nabble.com.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread bateivan

Thank you, Chris,

I tried your suggestion using regular connection. Unfortunately, I got the
same result.
See my reply to Isaak,s reply where I am going to post portion of my code to
visualize what I am talking about.

Thanx again


chris smith-9 wrote:
> 
> 
>> It means that either your mysql conenction details are not correctly set
>> or
>> the connection resource isn't accessible for your mysql functions. I
>> suggest
>> you first try by replacing:
>> 
>> $link = mysql_pconnect('localhost', 'root', 'testing');
>> 
>> into:
>> 
>> mysql_pconnect('localhost', 'root', 'testing');
> 
> Why? How is that going to help fix the problem?
> 
> Personally I'd say to *not* use persistent connections as it will cause
> you problems later.
> 
> Use a normal connection:
> 
> $link = mysql_connect($server, $user, $pass);
> 
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17989584.html
Sent from the Php - Database mailing list archive at Nabble.com.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] MSSQL and ODBC Connections with PHP on Windows

2008-06-18 Thread Wei, Alice J.
Hi,

   I am a newbie using the combination of PHP and MSSQL together.
   Can anyone tell me which method it might be better as far as using PHP on 
Windows with MSSQL database on a single machine? (The PHP and MSSQL database 
are not set up remotely on two different servers.

I have set up both, and my ODBC Driver does work when I run it from the 
test without using PHP, and yet when I put it in PHP, my entire screen goes 
blank.


$dsn="MSSQL";
$username="user";
$password="password";

$sqlconnect=odbc_connect($dsn,$username,$password);
$sqlquery="SELECT title FROM books";
$process=odbc_exec($sqlconnect, $sqlquery);

while(odbc_fetch_row($process)){
$Name = odbc_result($process,"Name");
echo "$Name"; }
odbc_close($sqlconnect);


The similar thing happens when I use the code by using a slight modification 
from http://us3.php.net/manual/en/function.mssql-connect.php.

Can anyone please provide me some tips and solutions on what additional modules 
or set up I need to get this to work? I was told that if I use Windows, I may 
not have to use FreeTDS.

Thanks in advance.
==
Alice Wei
MIS 2009
School of Library and Information Science
Indiana University Bloomington
[EMAIL PROTECTED]

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: PHP-MySQL connection for particular module

2008-06-18 Thread Isaak Malik
You're very welcome, I understand that you need a solution which allows you
to keep using the connection this way.

I doubt that your php.ini is the cause so I'll suggest the following:

Try executing your MySQL queries by passing the $link variable to the
function as the connection resource:

mysql_query("SELECT...", $link);

Something that also might cause it is that you use (include|require)_once
and that this module doesn't have access to the connection resource, if this
is the case change it into include|require and see if that solves your
issue. If not then could you please post some example code of your module if
possible so we can be more helpful?

Also be sure that you global $link; it in functions (I don't know if this
required since I didn't use it this way for a long while).

Could you also please answer to the list instead of directly to me as this
might also be informative for others.

On Tue, Jun 17, 2008 at 10:49 PM, <[EMAIL PROTECTED]> wrote:

> Thank you Isaak for interest in my subject.
>
> I have my connection set in a separate file which is included into the
> page. All my modules work except this one.
> When I use the following line
> $link = mysql_pconnect('localhost', 'root', 'testing');
> actually, my module starts working which is a redundant line as long as I
> have all this set in my include file.
> The thing is that I would like to keep this code in an included file for
> clearness and readability and make it work.
>
> Any idea why this is happening only to this module. May be, it requires
> change of some settings in php.ini or I am doing something wrong but the
> code is actually working when I introduce the line above.
> Tanx
>
> Isaak Malik-3 wrote:
> >
> > If you get an error of this kind:
> >
> > "Warning: mysql_query() [function.mysql-query]: Access denied for user
> > 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache
> > Software
> > Foundation\Apache2.2\htdocs\login.php on line 17
> >
> > Warning: mysql_query() [function.mysql-query]: A link to the server could
> > not be established in
> > D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on
> > line 17"
> >
> > It means that either your mysql conenction details are not correctly set
> > or
> > the connection resource isn't accessible for your mysql functions. I
> > suggest
> > you first try by replacing:
> >
> > $link = mysql_pconnect('localhost', 'root', 'testing');
> >
> > into:
> >
> > mysql_pconnect('localhost', 'root', 'testing');
> >
> > On 6/17/08, bateivan <[EMAIL PROTECTED]> wrote:
> >>
> >>
> >> Hello,
> >>
> >> First of all, please, have in mind that I am new in this business.
> >>
> >> I have a problem connecting with data base in one particular module.
> >> That's
> >> right. The rest of the modules can connect to db, update tables with new
> >> info but this one is refusing giving me message like this:
> >>
> >> "Warning: mysql_query() [function.mysql-query]: Access denied for user
> >> 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache
> >> Software
> >> Foundation\Apache2.2\htdocs\login.php on line 17
> >>
> >> Warning: mysql_query() [function.mysql-query]: A link to the server
> could
> >> not be established in
> >> D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php
> on
> >> line 17"
> >>
> >>
> >> It is a authentication module and this is the fragment of the code which
> >> is
> >> giving me a hard time:
> >>
> >>
> >>
> ***
> >>  >> include $_SERVER['DOCUMENT_ROOT'].
> >> '/layout.php';
> >>
> >> switch($_REQUEST['req']){
> >>
> >> case "validate":
> >>
> >>$validate = mysql_query("SELECT * FROM members
> >>WHERE username = '{$_POST['username']}'
> >>AND password = md5('{$_POST['password']}')"
> >>);
> >>
> >> etc
> >>
> >>
> >>
> ***
> >>
> >> My platform is WinXP on drive F:\ (I have Win'98 on C:\) and as you can
> >> see
> >> my program files are on D:\. All this may not be important but I listed
> >> anyway.
> >> It is installed Apache 2.2.6 using windows installer, PHP 5.2.6 (I just
> >> replaced 5.2.5 hoping to fix the problem), and MySQL 5.0.45.
> >>
> >> I am using persisten connection which should be on until you restart the
> >> server. I have a file included in every page for connection with MySQL
> >> and
> >> data base.
> >> PHP manual says that "mysql_query" reuses the existing connection or try
> >> to
> >> create one if not present (I think, according to the warning is trying
> to
> >> create one).
> >> I had been checking after each step using phpinfo() if the connection is
> >> there and it's there but for some reason the above fragment does not
> >> work.
> >> As I mentioned above the rest of my modules are working fine with mysql.
> >>
> >> I checked the "ph

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Isaak Malik
Because then the connection resource isn't stored in the $link variable and
you will be able to use the mysql functions without passing that variable to
each function.

On Wed, Jun 18, 2008 at 1:51 AM, Chris <[EMAIL PROTECTED]> wrote:

>
> > It means that either your mysql conenction details are not correctly set
> or
> > the connection resource isn't accessible for your mysql functions. I
> suggest
> > you first try by replacing:
> >
> > $link = mysql_pconnect('localhost', 'root', 'testing');
> >
> > into:
> >
> > mysql_pconnect('localhost', 'root', 'testing');
>
> Why? How is that going to help fix the problem?
>
> Personally I'd say to *not* use persistent connections as it will cause
> you problems later.
>
> Use a normal connection:
>
> $link = mysql_connect($server, $user, $pass);
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>



-- 
Isaak Malik
Web Developer