×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÍêÈ«ÕÆÎÕSwooleµÄЭ³ÌMySQLÉè¼Æ˼Ð÷ÓëÓ¦ÓÃʵ¼ù

swooleÊÇÒ»¿î»ùÓÚphpÓïÑԵĸßÐÔÄÜÍøÂçͨѶ¿ò¼Ü£¬ËüÖ§³Ötcp/udp/http/websocketµÈ¶àÖÖЭÒ飬ͬʱҲ֧³ÖЭ³ÌʵÏÖ¡£ÔÚ»¥ÁªÍø¼ÓËÙ¡¢ÎïÁªÍø¡¢ÓÎÏ·¿ª·¢¡¢´óÊý¾Ý´¦ÀíµÈÁìÓò£¬swooleÒѾ­³ÉΪÁËÖڶ࿪·¢ÕßµÄÊ×Ñ¡¿ò¼Ü¡£

ÔÚSwoole¿ò¼ÜÖУ¬Ð­³ÌMySQLÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄ×é¼þ¡£Ð­³ÌMySQLÌṩÁËÒ»ÖÖ¸ßЧ¡¢¼òÆӵķ½·¨À´ÅþÁ¬ºÍ²Ù×÷MySQLÊý¾Ý¿â¡£Ïà½ÏÓڹŰåµÄMySQLÅþÁ¬·½·¨£¬Ð­³ÌMySQLÔÚÐÔÄÜÉÏÓÐ×ÅÏÔ×ŵÄÓÅÊÆ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«Ì½ÌÖSwooleµÄЭ³ÌMySQLÉè¼Æ˼Ð÷ÓëÓ¦ÓÃʵ¼ù£¬×ÊÖú¶ÁÕ߸üºÃµØÕÆÎÕÕâÒ»Ö÷Òª×é¼þ¡£

Ò»¡¢Ð­³ÌMySQLµÄÉè¼Æ˼Ð÷

Э³ÌMySQLµÄÉè¼Æ˼Ð÷Ö÷Òª·ÖΪÁ½¸ö·½Ã棺

³¤ÅþÁ¬ÓëÅþÁ¬³Ø

Э³ÌMySQLʹÓó¤ÅþÁ¬ºÍÅþÁ¬³ØʵÏÖ¸ßЧµÄÊý¾Ý¿âÅþÁ¬¡£³¤ÅþÁ¬ÊÇÖ¸ÅþÁ¬MySQLÊý¾Ý¿âµÄ»ù´¡TCPÅþÁ¬Ò»Ö±¼á³Ö×ÅÒ»Ö±¿ª£¬Ö±µ½Àú³ÌÍ˳ö»òÕßÊÖ¶¯¹Ø±Õ¡£ÕâÑù¿ÉÒÔïÔ̭ÿ´ÎÇëÇóʱÖØн¨ÉèTCPÅþÁ¬µÄ¿ªÏú£¬Ìá¸ßÅþÁ¬Ð§ÂÊ¡£ÅþÁ¬³ØÔòÊÇΪÁ˳ä·ÖʹÓÃÅþÁ¬×ÊÔ´£¬½«ÅþÁ¬³ØÖеÄÅþÁ¬Æ¾Ö¤Ò»¶¨Õ½ÂÔ¾ÙÐзÖÅÉ¡£Í¨¹ýÅþÁ¬³Ø£¬¿ÉÒÔ¿ØÖÆÅþÁ¬µÄÊýÄ¿ºÍÓÐÓÃÆڵȣ¬×èÖ¹Êý¾Ý¿âµÄÅþÁ¬×ÊÔ´±»ºÄ¾¡¡£

Òì²½IOÓëЭ³Ì

Э³ÌMySQLʹÓÃÒì²½IOºÍЭ³ÌʵÏÖ¸ßЧµÄIO´¦Àí¡£¹Å°åµÄMySQLÅþÁ¬ÊÇͬ²½µÄ£¬Ò²¾ÍÊÇ˵ÔÚÖ´ÐÐÒ»¸öSQLÅÌÎÊʱ»áÒ»Ö±ÆÚ´ýÖ±µ½ÅÌÎÊЧ¹û·µ»Ø¡£¶øЭ³ÌMySQLʹÓÃÁËЭ³ÌºÍÒì²½IOÊÖÒÕ£¬½«Êý¾ÝÇëÇóÓë´¦ÀíÊèÉ¢¿ªÀ´£¬Ê¹µÃÅÌÎÊÇëÇó¿ÉÒÔÔÚ·¢ËͺóÁ¬Ã¦¾ÙÐÐÏÂÒ»´ÎÅÌÎÊ»òÕßÆäËû²Ù×÷£¬²»ÐèÒªÆÚ´ýÅÌÎÊЧ¹û¡£µ±ÅÌÎÊЧ¹û·µ»Øʱ£¬Ð­³ÌMySQL»á×Ô¶¯´¥·¢Ð­³Ì»Ö¸´£¬²¢½«Ð§¹ûת´ï¸øЭ³Ì¾ÙÐд¦Àí¡£

¶þ¡¢Ð­³ÌMySQLµÄÓ¦ÓÃʵ¼ù

ÔÚSwoole¿ò¼ÜÖУ¬Ê¹ÓÃЭ³ÌMySQLÒ²ºÜÊǼòÆÓ¡£ÏÂÃæÎÒÃǽ«Í¨¹ýÒ»¸ö¼òÆÓʾÀý£¬À´ÑÝʾЭ³ÌMySQLµÄ»ù±¾Ó¦Óá£

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚSwooleÖÐÆôÓÃЭ³ÌMySQLÀ©Õ¹£¬¿ÉÒÔͨ¹ýÒÔÏ´úÂë¾ÙÐÐʵÏÖ£º

Coun(function() {
    $mysql = new SwooleCoroutineMySQL();
    $mysql->connect([
        'host' => '127.0.0.1',
        'user' => 'root',
        'password' => 'root',
        'database' => 'test_db',
    ]);
});

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃÇÊ×ÏÈʹÓÃCoun½¨ÉèÁËÒ»¸öЭ³Ì£¬È»ºóͨ¹ýSwooleCoroutineMySQL£¨SwooleÖеÄЭ³ÌMySQLÀࣩ½¨ÉèÁËÒ»¸öMySQLÅþÁ¬¡£ÆäÖУ¬connectÒªÁìÖÐÉèÖÃÁËMySQLµÄÅþÁ¬²ÎÊý¡£Í¨¹ýÕâ¸öʾÀý£¬ÎÒÃÇʵÏÖÁËÒ»¸ö¼òÆÓµÄMySQLÅþÁ¬£¬²¢ÇÒ¿ÉÒÔ×îÏȾÙÐÐÊý¾ÝµÄ¶Áд²Ù×÷¡£

½ÓÏÂÀ´£¬ÎÒÃǽ«ÑÝʾÔõÑù¾ÙÐÐMySQLÊý¾Ý¿âµÄÅÌÎʲÙ×÷¡£ÒÔÏÂÊÇʾÀý´úÂ룺

Coun(function () {
    $mysql = new SwooleCoroutineMySQL();
    $mysql->connect([
        'host' => '127.0.0.1',
        'user' => 'root',
        'password' => 'root',
        'database' => 'test',
    ]);
    $result = $mysql->query('SELECT * FROM users where id = 1');
    var_dump($result);
});

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃÇͨ¹ýqueryÒªÁìʵÏÖÁËÒ»¸ö»ù±¾µÄÅÌÎʲÙ×÷£¬ÅÌÎÊusers±íÖÐidΪ1µÄ¼Í¼£¬²¢½«ÅÌÎÊЧ¹ûÊä³ö¡£

×îºó£¬ÎÒÃǽ«½²ÊöÔõÑù¾ÙÐÐMySQLÊý¾Ý¿âµÄдÈë²Ù×÷¡£ÒÔÏÂÊÇʾÀý´úÂ룺

Coun(function () {
    $mysql = new SwooleCoroutineMySQL();
    $mysql->connect([
        'host' => '127.0.0.1',
        'user' => 'root',
        'password' => 'root',
        'database' => 'test',
    ]);
    $data = ['name' => 'user1', 'password' => 'pwd1'];
    $tableName = 'users';
    $keys = implode(',', array_keys($data));
    $values = implode(',', array_fill(0, count($data), '?'));
    $sql = "INSERT INTO `{$tableName}` ({$keys}) VALUES ({$values})";
    $params = array_values($data);
    $result = $mysql->prepare($sql)->execute($params);
    var_dump($result);
});

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃÇͨ¹ýprepareÒªÁìºÍexecuteÒªÁìʵÏÖÁËÒ»¸ö»ù±¾µÄSQLдÈë²Ù×÷¡£prepareÒªÁì¿ÉÒÔ½¨ÉèÒ»¸öÔ¤´¦ÀíÓï¾ä£¬½«SQLºÍÐè°ó¶¨µÄ²ÎÊý´«È룬·µ»ØÒ»¸öЭ³ÌMySQLÔ¤´¦Àí¹¤¾ß¡£execute·½¹æÔòÊÇÖ´ÐÐÔ¤´¦ÀíÓï¾ä£¬²¢·µ»ØÖ´ÐÐЧ¹û¡£

×ܽá

Э³ÌMySQLÊÇSwoole¿ò¼ÜÖкÜÊÇÖ÷ÒªµÄÄ£¿é£¬ËüʹÓÃÁ˳¤ÅþÁ¬¡¢ÅþÁ¬³Ø¡¢Òì²½IOºÍЭ³ÌµÈÊÖÒÕ£¬ÊµÏÖÁ˸ßЧ¡¢Îȹ̵ÄMySQLÅþÁ¬Óë¶Áд²Ù×÷¡£Í¨¹ý±¾ÎĵÄÏÈÈÝ£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÏàʶЭ³ÌMySQLµÄÉè¼Æ˼Ð÷ºÍÓ¦ÓÃʵ¼ù£¬´Ó¶ø¸üºÃµØÕÆÎÕЭ³ÌMySQLµÄʹÓÃÒªÁì¡£

ÒÔÉϾÍÊÇÍêÈ«ÕÆÎÕSwooleµÄЭ³ÌMySQLÉè¼Æ˼Ð÷ÓëÓ¦ÓÃʵ¼ùµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ