نمایش نتایج 1 تا 5 از 5

نام تاپیک: mysqli و PDO در دیتابیس

  1. #1
    کاربر دائمی
    تاریخ عضویت
    اردیبهشت 1389
    محل زندگی
    تهران
    پست
    178

    Question mysqli و PDO در دیتابیس

    سلام

    دوستان من یک کلاس برای کار با دیتابیس تهیه کردم این کلاس در ورژن 2.4 وب سرور wamp بدون مشکل کار میکرد اما وقتی wamp 2.5 ریختم میگه این دستورات منسوخ شده

    کلاس دیتابیس من:

    <?phpclass database{ var $last_query; //Saved result of the last query made var $last_result; //Results of the last query made var $func_call; //A textual description of the last query/get_row/get_var call var $link; //database link var $lastquery; //last query var $result; //query result // Connect to MySQL database function database($DB_NAME,$DB_USER,$DB_PASS) { $this->link=mysql_connect(DB_HOST, $DB_USER, $DB_PASS) or die('ارتباط با سرور ممکن نیست'.'<br>'.'لطفا چند دقیقه دیگر دوباره سعی کنید'.'<br>'.'در صورت رفع نشدن مشکل به تیم پشتیبانی سایت در قسمت تماس با ما اطلاع دهید'.'<br>'.'با تشکر'); //Set All Charsets to UTF8 mysql_query("SET character_set_results=utf8 , character_set_client=utf8 , character_set_connection=utf8 , character_set_database=utf8 , character_set_server=utf8"); mysql_select_db($DB_NAME) or die('خطا در برقراری ارتباط'.'<br>'.'لطفا چند دقیقه دیگر دوباره سعی کنید'.'<br>'.'در صورت رفع نشدن مشکل به تیم پشتیبانی سایت در قسمت تماس با ما اطلاع دهید'.'<br>'.'با تشکر'); } /** Query the database. * @param $query The query. * @return The result of the query into $lastquery, to use with fetchNextObject(). */ function query( $query ){ $this->lastquery=$query; $this->result=@mysql_query( $query, $this->link ); return $this->result; } /** Do the same as query() but do not return nor store result. * Should be used for INSERT, UPDATE, DELETE... * @param $query The query. * @param $debug If true, it output the query and the resulting table. */ function execute($query){ @mysql_query($query); } /** Convenient method for mysql_fetch_object(). * @param $result The ressource returned by query(). * @return An ARRAY representing a data row. */ function fetchArray($result){ if ($result == NULL) $result = $this->result; if ($result == NULL || mysql_num_rows($result) < 1) return NULL; else return mysql_fetch_assoc($result); } /** Close the connecion with the database server. * It's usually unneeded since PHP do it automatically at script end. */ function close(){ mysql_close($this->link); } /** Get the number of rows of a query. * @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used. * @return The number of rows of the query (0 or more). */ function numRows($result = NULL){ if ($result == NULL) return @mysql_num_rows($this->result); else return mysql_num_rows($result); }}?>




    تا انجایی که گشتم فهیدم @ باید حذف کنم مثل اینکه منسوخ شده در ورژن جدید php
    مورد دیگه اینکه میگه باید از mysqli یا PDO استفاده کنم برای کار با دیتابیسیه مثال در این لینک زده :
    http://php.net/manual/en/mysqlinfo.api.choosing.php
    ولی نمیدونم من چطوری کد خودم رو با مثال بالا به روز کنم
    نمیخوام نام و ورودی های کلاسم عوض شه چون در این صورت کل قسمتهایی که در پروژه خودم از این کلاس استفاده کردم باید تغییر بدم


    اگه میشه کمک کنید آپدیت شده کلاس خودم با کمک mysqli بنویسم

  2. #2
    کاربر دائمی آواتار kabootar_y
    تاریخ عضویت
    خرداد 1393
    محل زندگی
    ایران/اصفهان
    پست
    234

    نقل قول: mysqli و PDO در دیتابیس

    من ویرایشش کردم ولی تست نکردم احتمالا خطا نداشته باشه
    اگه خطا داشت بگو تا مشکلش رو بر طرف کنم


    <?php
    class database{ var $last_query;//Saved result of the last query made var $last_result; //Results of the last query made var $func_call; //A textual description of the last query/get_row/get_var call var $link; //database link var $lastquery; //last query var $result; //query result // Connect to MySQL database function database($DB_NAME,$DB_USER,$DB_PASS) { $this->link=mysqli_connect(DB_HOST, $DB_USER, $DB_PASS,$DB_NAME) or die('ارتباط با سرور ممکن نیست'.''.'لطفا چند دقیقه دیگر دوباره سعی کنید'.''.'در صورت رفع نشدن مشکل به تیم پشتیبانی سایت در قسمت تماس با ما اطلاع دهید'.''.'با تشکر'); //Set All Charsets to UTF8 mysqli_query("SET character_set_results=utf8 , character_set_client=utf8 , character_set_connection=utf8 , character_set_database=utf8 , character_set_server=utf8"); } /** Query the database. * @param $query The query. * @return The result of the query into $lastquery, to use with fetchNextObject(). */ function query( $query ) { $this->lastquery=$query; $this->result=mysqli_query( $query, $this->link ); return $this->result; } /** Do the same as query() but do not return nor store result. * Should be used for INSERT, UPDATE, DELETE... * @param $query The query. * @param $debug If true, it output the query and the resulting table. */ function execute($query) { mysqli_query($query); } /** Convenient method for mysqli_fetch_object(). * @param $result The ressource returned by query(). * @return An ARRAY representing a data row. */ function fetchArray($result) { if ($result == NULL) $result = $this->result; if ($result == NULL || mysqli_num_rows($result) < 1) return NULL; else return mysqli_fetch_assoc($result); } /** Close the connecion with the database server. * It's usually unneeded since PHP do it automatically at script end. */ function close() { mysqli_close($this->link); } /** Get the number of rows of a query. * @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used. * @return The number of rows of the query (0 or more). */ function numRows($result = NULL) { if ($result == NULL)return mysqli_num_rows($this->result); else return mysqli_num_rows($result); }}
    ?>

  3. #3
    کاربر دائمی
    تاریخ عضویت
    اردیبهشت 1389
    محل زندگی
    تهران
    پست
    178

    نقل قول: mysqli و PDO در دیتابیس

    نقل قول نوشته شده توسط kabootar_y مشاهده تاپیک
    من ویرایشش کردم ولی تست نکردم احتمالا خطا نداشته باشه
    اگه خطا داشت بگو تا مشکلش رو بر طرف کنم


    <?php
    class database{ var $last_query;//Saved result of the last query made var $last_result; //Results of the last query made var $func_call; //A textual description of the last query/get_row/get_var call var $link; //database link var $lastquery; //last query var $result; //query result // Connect to MySQL database function database($DB_NAME,$DB_USER,$DB_PASS) { $this->link=mysqli_connect(DB_HOST, $DB_USER, $DB_PASS,$DB_NAME) or die('ارتباط با سرور ممکن نیست'.''.'لطفا چند دقیقه دیگر دوباره سعی کنید'.''.'در صورت رفع نشدن مشکل به تیم پشتیبانی سایت در قسمت تماس با ما اطلاع دهید'.''.'با تشکر'); //Set All Charsets to UTF8 mysqli_query("SET character_set_results=utf8 , character_set_client=utf8 , character_set_connection=utf8 , character_set_database=utf8 , character_set_server=utf8"); } /** Query the database. * @param $query The query. * @return The result of the query into $lastquery, to use with fetchNextObject(). */ function query( $query ) { $this->lastquery=$query; $this->result=mysqli_query( $query, $this->link ); return $this->result; } /** Do the same as query() but do not return nor store result. * Should be used for INSERT, UPDATE, DELETE... * @param $query The query. * @param $debug If true, it output the query and the resulting table. */ function execute($query) { mysqli_query($query); } /** Convenient method for mysqli_fetch_object(). * @param $result The ressource returned by query(). * @return An ARRAY representing a data row. */ function fetchArray($result) { if ($result == NULL) $result = $this->result; if ($result == NULL || mysqli_num_rows($result) < 1) return NULL; else return mysqli_fetch_assoc($result); } /** Close the connecion with the database server. * It's usually unneeded since PHP do it automatically at script end. */ function close() { mysqli_close($this->link); } /** Get the number of rows of a query. * @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used. * @return The number of rows of the query (0 or more). */ function numRows($result = NULL) { if ($result == NULL)return mysqli_num_rows($this->result); else return mysqli_num_rows($result); }}
    ?>


    خطا میده برای

    ( ! )
    Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\p\class-database.php on line 14


    mysqli_query("SET character_set_results=utf8 , character_set_client=utf8 , character_set_connection=utf8 , character_set_database=utf8 , character_set_server=utf8");

  4. #4
    کاربر دائمی
    تاریخ عضویت
    اردیبهشت 1389
    محل زندگی
    تهران
    پست
    178

    نقل قول: mysqli و PDO در دیتابیس

    اگه برای کلاس من مثال pdo بتونی بزنی ممنون میشم

  5. #5
    کاربر دائمی آواتار kabootar_y
    تاریخ عضویت
    خرداد 1393
    محل زندگی
    ایران/اصفهان
    پست
    234

    نقل قول: mysqli و PDO در دیتابیس

    ویرایشش کردم ولی بازم به دلیل کمبود وقت تستش نکردم
    اگه مشکل داشت بازم در خدمتم
    راستی گفتی PDO اگه بخوای اینو کلاس رو به PDO تغییر بدی از نگاه امنیت و ... فرقی نمی کنه و اگه بخوای بحث های امنیتی رو که معمولا در استفاده از PDO استفاده میشه رو در نظر بگیری باید هرجایی که از کلاس database و متدهاش استفاده کردی رو هم تغییر بدی که فکر می کنم لازم نیست همین که بتونی از mysqli استفاده کنی فکر می کنم کافی باشه (((( البته این پیشنهاد منه بر اساس تجربیات خودم))))



    <?phpclass database{ var $last_query;//Saved result of the last query made var $last_result; //Results of the last query made var $func_call; //A textual description of the last query/get_row/get_var call var $link; //database link var $lastquery; //last query var $result; //query result // Connect to MySQL database function database($DB_NAME,$DB_USER,$DB_PASS) { $this->link=mysqli_connect(DB_HOST, $DB_USER, $DB_PASS,$DB_NAME) or die('ارتباط با سرور ممکن نیست'.''.'لطفا چند دقیقه دیگر دوباره سعی کنید'.''.'در صورت رفع نشدن مشکل به تیم پشتیبانی سایت در قسمت تماس با ما اطلاع دهید'.''.'با تشکر'); //Set All Charsets to UTF8 mysqli_query($this->link, "SET character_set_results=utf8 , character_set_client=utf8 , character_set_connection=utf8 , character_set_database=utf8 , character_set_server=utf8"); } /** Query the database. * @param $query The query. * @return The result of the query into $lastquery, to use with fetchNextObject(). */ function query( $query ) { $this->lastquery=$query; $this->result=mysqli_query($this->link, $query, $this->link ); return $this->result; } /** Do the same as query() but do not return nor store result. * Should be used for INSERT, UPDATE, DELETE... * @param $query The query. * @param $debug If true, it output the query and the resulting table. */ function execute($query) { mysqli_query($this->link, $query); } /** Convenient method for mysqli_fetch_object(). * @param $result The ressource returned by query(). * @return An ARRAY representing a data row. */ function fetchArray($result) { if ($result == NULL) $result = $this->result; if ($result == NULL || mysqli_num_rows($result) < 1) return NULL; else return mysqli_fetch_assoc($result); } /** Close the connecion with the database server. * It's usually unneeded since PHP do it automatically at script end. */ function close() { mysqli_close($this->link); } /** Get the number of rows of a query. * @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used. * @return The number of rows of the query (0 or more). */ function numRows($result = NULL) { if ($result == NULL)return mysqli_num_rows($this->result); else return mysqli_num_rows($result); }}?>

تاپیک های مشابه

  1. پاسخ: 1
    آخرین پست: چهارشنبه 02 شهریور 1390, 14:36 عصر
  2. پاسخ: 0
    آخرین پست: چهارشنبه 20 بهمن 1389, 16:56 عصر
  3. پاسخ: 2
    آخرین پست: چهارشنبه 17 آذر 1389, 20:08 عصر
  4. سوال: mysqli
    نوشته شده توسط navidwhacker در بخش PHP
    پاسخ: 1
    آخرین پست: سه شنبه 31 فروردین 1389, 20:16 عصر
  5. سوال: mysqli
    نوشته شده توسط mostafa8266 در بخش PHP
    پاسخ: 1
    آخرین پست: جمعه 04 اردیبهشت 1388, 01:59 صبح

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •