PDA

نسخه کامل مشاهده نسخه کامل : مشکل در برقراری ارتباط php با MySQL



siavosh1
17-12-2007, 16:33
نمی دونم چرا وقتی از دستور
mysql_connect(); می کنم هیچ کار خاصی انجام نمیده و یا احتمالاً بانک باز نمیشه و کلاً هیچ عکس العمل خاصی اتفاق نمی افته... توی چند تا از بنامه هایی که نوشتم هر کاری می کنم با Mysql از طریق php تماس برقرار کنم نشد :2:

my friend
17-12-2007, 18:55
کدهایی که نوشتی رو اینجا بزار تا ببینیم قضیه از چه قراره...
راستی ، دیتابیس رو اجرا میکنی؟!

برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید

برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید

siavosh1
18-12-2007, 13:01
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید

اگر منظورت همون درخواست یا انتخاب دیتابیس هست بله ... البته توی کدهای بالا نگاه کن همه چی دستگیرت میشه.. ولی موقعی که برنامه رو اجرا می کنم مقدار متغیری که برای دستور mysql_conect در نظر گرفتم هیچ تغییری نمی کنه.. چون اگر حتی مقدار 0 رو هم برگردونه باید طبق دستور if یک error رو چاپ کنه:13:

نمی دونم اشکال از کجاس !! توی mysql help رو هم نگاه کردم دیدم نوشته بود که به جای دستور mysql_conect از دستور mysql_real_conect استفاده کنید و ظاهراً این دستور جایگزین دستور قبلی شده ولی وقتی این کار رو هم انجام دادم هیچ اتفاقی نیافتاد . شاید برای ارتباط mysql و php باید تنظیماتی انجام بدم !!
ورژن هر دو برنامه رو مینویسم شاید بهتر بتونید کمک کنید:10:
Mysql server 5.0
PHP 5.2.3.3

peyman1987
18-12-2007, 23:04
عزیز جان شما نمیتونی از این دستور بدون دادن مقادیر مناسب بهش استفاده کنی. نحوه درست استفاده از دستور به این شکله.


برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
حالا باید بجای server آدرس سروری که دیتابیس روش هست بجای usernaem نام کاربری مروبط به خدت روی سرور و بجای password رمزت رو وارد کنی. مثلا اگه خواستی به دیتابیسی که روی سیستم خودته وصل بشی باید دستورت رو اینجوری بنویسی.


برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید

my friend
18-12-2007, 23:13
پیمان جان ، معذرت میخوام...
صفحه رو نگه داشته بودم که کدها رو سر فرصت تست کنم ، یادم رفت رفرش کنم تا ببینم جوابی داده شده یا نه...

برای خالی نبودن عریضه : تابع ()mysql_connect ، پنج آرگومان اختیاری (و نه اجباری!) میگیره که در اکثر مواقع باید تنظیم بشن:

برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید

siavosh1
21-12-2007, 19:09
دست همگی درد نکنه !! مشکل حل شد .:46: اما علتهاش زیاد بود که یکی از اونها دادن مقادیر بود که البته برای کانکت به mysql مقدار داده بودم ولی بازم وصل نشده بود . روش حل ا.نو اینجا می گم تا دوستایی هم که این مشکل براشون پیش میاد بتونن حلش کنن ..
در واقع علت عدم کانکت بین php و mysql من به خاطر ورژن هاییه که استفاده کردم
این رو بعد از کلی پرسو جو فهمیدم و به این خاطره که در نسخه های php و mysql ورژن 5 به بعد ارتباط بین php و mysql به طور اتوماتیک برقرار نمیشه (بر عکس نسخه های قبلی) و علت هم داره... طبق گفته های خود php manual 5 یکی از علت هاش اینه که مثلا موقع نصب برنامه هایی مثل Dreamwiever یا غیره ممکن هست چند تا نسخه php یا mysql روی سیستم موجود باشه و این باعث کاهش سرعت و مشکلهایی میشد که دیگه ترجیح داده شده ارتباط بین php و mysql به صورت دستی تنظیم بشه البته یه توضیحاتی توی php manual و mysql manual هم داده شده ولی روش اصلی حلشو از توی یه فروم mysql پیدا کردم که نسخه انگلسیشو میذارم تا همه ازش استفاده کنم .. شاید نسخه ترجمه شدشو هم گذاشتم ... حتما بخونید چون خیلی مهمه و مشکله خیلیها بوده که از ورژن های جدید php و mysql استفاده می کردن :



Posted by: powder skier ()
Date: April 01, 2007 11:25AM


- Installed Apache 2.24 first, then PHP 5.21 through the php-5.2.1-win32-installer.msi file & finally MySQL 5.0.37 for local site testing for web development onto a Windows XP SP2 PC. The key here was that PHP 5.21 was installed using the .msi file versus downloading then extracting the contents of the php-5.2.1-Win32.zip file into a folder on my PC. Since I installed from the .msi file, I noticed 2 things after some research. First, the ext folder, where PHP extensions are referenced was not installed, secondly the libmysql.dll file was not installed with the msi file. The libmysql.dll file is also included in the php-5.2.1-Win32.zip file. This file seems to come into play later, as you will see. I confirmed Apache worked with localhost test(go to
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید make sure you see It works! on the webpage), confirmed php worked with phpinfo test(create a file named file.php with the following contents in the code <?php phpinfo(); ?> this file will show you php configuration information then I confirmed that MySQL was starting the MySQL service as needed and I could login without issue as the root user.

- Next, I proceeded to try to connect to a MySQL database through Dreamweaver 8(8.0.2) on my PC. I received the “Your PHP server doesn’t have the MySQL module loaded or you can’t use the mysql_(p)connect functions.” error message.

- Next, I checked my php.ini file(located in your PHP installation folder) to see if the extension_dir value was set to reference the folder where my PHP extensions would reside and if the extension=php_mysql.dll was enabled and accessible to PHP so that it could interface to MySQL. The extension_dir value was pointing to ‘./ ’ . Next, I proceeded to search my local hard drive where PHP was installed for the ext folder, where PHP extensions reside. To my surprise, this folder was not found. After some searching online, I discovered that the ext folder was in the php-5.2.1-Win32.zip file that can be downloaded from the PHP site. So I proceeded to download this file to my PC, extract the contents of the file into a folder then copy the ext folder into my PHP installation folder. In my instance, PHP was installed to E:\Program Files\PHP\ and I copied the ext folder here. So it was located here; E:\Program Files\PHP\ext. Now I had to go back to my php.ini file and specify the location of the ext folder, I did that, checked the phpinfo page for the location where extension_dir was pointing, it was still referencing ‘ ./ ’ . I proceeded to restart my PC, then I checked this value once again after a reboot and it was pointing to the correct location(E:\Program Files\PHP\ext).

- Next, I needed to confirm that the extension=php_mysql.dll was enabled in the php.ini file, it was commented out( ;extension=php_mysql.dll ), I removed the comment( extension=php_mysql.dll ) and tried to connect to the MySQL database again through Dreamweaver and it still gave the same error message as above.

- I went online again and searched the PHP site in relation to setting it up with MySQL 5 and PHP 5. The site stated that the PHP installation location should be the first value specified in the PATH variables on your Windows system. I checked this by going to Control Panel->System->Advanced->Environment Variables then in the System Variables section I confirmed that the Path Variable had the E:\Program Files\PHP\; value listed first, this is needed according to the PHP site and I confirmed this. Secondly, I confirmed that there was a variable named PHPRC pointing to my PHP installation location
(E:\Program Files\PHP\ ). This was also listed as something that should be specified.

- The PHP site also stated that the libmysql.dll file is needed in your C:\Windows\System32 folder. Next step was to search my PC for this file, it was not in C:\Windows\System32 or in my PHP installation folder. However, this file was located in the folder that contained the extracted files from the php-5.2.1-Win32.zip file. I proceeded to copy the libmysql.dll file into C:\Windows\System32, tried to connect to MySQL in Dreamweaver 8 again, still the same error message as above. Then, I thought I should try to Stop my Apache server, then Start it. After this was done, I tried to connect to the MySQL in Dreamweaver 8 and this time it worked.

- This is a long and winded explanation, but I believe that each of the steps are necessary to confirm that you have the prerequisite functionality and files for this setup(Apache 2.24, PHP 5.21, MySQL 5.0.37) to work on a Windows PC. I wanted to post this online to save people frustration if they encountered the specific error as I did. I had read that other people downgraded to PHP 4 and this resolved the problem, but that didn’t cut it for me. I have used XAMPP, a free local development environment and found this much simpler to install and start to use than the above configuration. But for those who have the problem I had, I hope my steps helped. If you find a fix, post it online to help others.